﻿@page
@inject ContentService _contentService
@inject UserService _userService
@{
    ViewBag.Title = "首页";
    //Layout = "/Pages/Shared/_Layout.cshtml";


    var query = new ContentPageQuery(Request.Query["page"].ToString().To(1))
    {
        IncludeSecret = false
    };

    if (Request.Query["channel"].Any())
    {
        query.Channel = (Enum.Parse<Channels>(Request.Query["channel"].ToString(), true));

    }


    var all = _contentService.GetContentsAsync(query).Result;
    var hot = _contentService.GetTopContentQueable(ContentQuery.Default).OrderByDescending(m => m.VisitNum).ToList();

    var mostContentUsers = _userService.GetUserRankAsync(5, m => m.Contents.Count()).Result;
}

<div class="row">
    <div class="col-md-9 col-sm-12">
        @Html.Partial("Content/_ListGroup",all)
        <div class="mt-3">
            @Html.Pagination(all)
        </div>
    </div>
    <div class="col-md-3 col-lg-3 d-none d-sm-block">

        <div class="row mt-3">
            <div class="w-100">
                <form asp-page="/Content/Search" method="get">
                    <div class="input-group">
                        <input type="text" name="keyword" class="form-control" placeholder="关键字" />
                        <div class="input-group-append">
                            <button type="submit" class="btn btn-dark"><i class="fa fa-search"></i></button>
                        </div>
                    </div>
                </form>
            </div>
        </div>


        <div class="row mt-3 border bg-light pt-3">
            <div class="col-12">
                <h4>热门帖子</h4>
                <hr />
                @Html.Partial("Content/_ListUnstyled", hot)
            </div>
        </div>
        <div class="row mt-3 pt-3">
            <div class="col-12">
                <h4>作家榜</h4>
                <hr />
                <ul class="list-unstyled">
                    @{ var contentIndex = 1;
                    foreach (var item in mostContentUsers)
                    {
                        <li class="border-bottom pb-3 pt-3">
                            <div class="float-left w-75">
                                @Html.RenderRankBadge(contentIndex)
                                <a target="_blank" asp-page="/user/index" asp-route-userId="@item.Id"><img src="@item.AvatarUrl" class="img-avatar-16" /> @(item.UserName)</a>
                                <div class="mt-1 text-sm text-muted" title="@item.Signature">
                                    @item.Signature?.Substring(0,36,"...")
                                </div>
                            </div>
                            <div class="float-right">
                                <i class="fa fa-book text-info" title="帖子数"></i> @(item.Contents.Count())
                            </div>
                            <div class="clearfix">
                            </div>
                        </li>
                    contentIndex++;
                }
                    }
                </ul>
            </div>
        </div>
        <div class="row mt-3">
            <div class="col-12">
                <h4>土豪榜</h4>
                <hr />
                <ul class="list-unstyled">
                    @{ var tradingPointIndex = 1;
                    foreach (var item in (await _userService.GetTopUserAsync(5, Infrastructure.UserTopOrderBy.TradingPointsDesc)))
                    {
                        <li class="border-bottom pb-3 pt-3">
                            <div class="float-left">
                                @Html.RenderRankBadge(tradingPointIndex)
                                <a target="_blank" asp-page="/user/index" asp-route-userId="@item.Id"><img src="@item.AvatarUrl" class="img-avatar-16" /> @(item.UserName)</a>
                            </div>
                            <div class="float-right">
                                <i class="fa fa-database text-golden"></i> @(item.TradingPoints)
                            </div>
                            <div class="clearfix">
                            </div>
                        </li>
                    tradingPointIndex++;
                }
                    }
                </ul>
            </div>
        </div>
    </div>
</div>